package com.cci.kangdao.wechatOrder.controller;

import com.cci.kangdao.utilTool.ParameterTool;
import com.cci.kangdao.wechatOrder.dto.request.WeChatJsConfigRequest;
import com.cci.kangdao.wechatOrder.exception.NotCheckException;
import com.cci.kangdao.wechatOrder.service.IWxChatSdkService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @description:
 * @author: zyf
 * @create: 2021-04-05
 */
@Controller
public class WeChatJSSDKController {
    @Resource
    private IWxChatSdkService wxChatSdkService;

    @RequestMapping(value = "/jsSdkConfig.aspx",method = RequestMethod.POST)
    public void jsCallBack(WeChatJsConfigRequest configRequest,HttpServletRequest request,
                           HttpServletResponse response){
        try{
            //调用服务
           Map<String,String > result = wxChatSdkService.getJsConfig(configRequest,request,response);
            ParameterTool.writeSuccessResponse(response,result);
        }catch (NotCheckException e){
            e.printStackTrace();
            ParameterTool.writeResponse(response,-e.getCode(),e.getMessage());
        }
        catch (Exception e){
            e.printStackTrace();
            ParameterTool.writeResponse(response,-99,"获取JSconfig失败");
        }
    }
}
